﻿using System.Reflection.PortableExecutable;
using System;
using System.Windows;
using AntMovement.Parameter;
using AntMovement.Core.IParameter;
using AntMovement.Core;

namespace AntMovement.Views
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void MinimizeClick(object sender, RoutedEventArgs e)
        {
            WindowState = WindowState.Minimized;
        }

        private void MaximizeClick(object sender, RoutedEventArgs e)
        {
            WindowState = WindowState.Maximized;
        }

        private void RestoreDownClick(object sender, RoutedEventArgs e)
        {
            WindowState = WindowState.Normal;
        }

        private void CloseClick(object sender, RoutedEventArgs e)
        {
            var app = App.Current as App;
            TemporaryParameter temporary = (TemporaryParameter)app.Container.Resolve(typeof(ITemporaryParameter));
            if (temporary.Status_Software)
            {
                IDialogHost dialogHost = (IDialogHost)app.Container.Resolve(typeof(IDialogHost));
                dialogHost.DialogShow("请先停止板卡链接！！！", Core.Enum.LogLevel.Warning, hostDialog: Core.Enum.PopUpType.Global);
                return;
            }
            Close();
        }

        private void WindowStateChanged(object sender, EventArgs e)
        {
            SetCaptionHeight();
        }

        private void HeaderSizeChanged(object sender, SizeChangedEventArgs e)
        {
            SetCaptionHeight();
        }

        private void SetCaptionHeight()
        {
            switch (WindowState)
            {
                case WindowState.Normal:
                    chrome.CaptionHeight = header.ActualHeight + BorderThickness.Top - chrome.ResizeBorderThickness.Top;
                    break;
                case WindowState.Maximized:
                    chrome.CaptionHeight = header.ActualHeight - BorderThickness.Top;
                    break;
            }
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            WindowState = WindowState.Maximized;
        }
    }
}
